package battleGame;

import java.lang.String;
import java.util.Collections;
import java.util.Vector;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Random;

public class Utils 
{
	static Random rand = new Random();
	
	static boolean fIsObjectInSight( Warrior warrior, GameObject target )
	{
		double distance = Vector2.minus( warrior.position, target.position ).magnitude();
		return distance <= warrior.sightDistance;
	}
	
	static boolean fIsWarriorInAttackRange( Warrior warrior, Warrior target )
	{
		return Vector2.minus( warrior.position, target.position ).magnitude() < ( warrior.attackRadius + target.spaceRadius ); 
	}

	static void Assert( boolean condition, String message )
	{
		//if( !condition )
			//error message
	}
	
	static Vector2 promediarPosiciones( Vector< Warrior > todos )
	{
		Vector2 sumatoria = new Vector2(0, 0);
		for( int i = 0; i < todos.size(); i++ )
			sumatoria = Vector2.suma( sumatoria, todos.get( i ).position );
		return Vector2.mul( sumatoria, todos.size() );
	}
	
	
	  static ArrayList<GameObject> quick_srt(Vector<GameObject> list)
	  {   
		  ArrayList<GameObject> warriorList = new ArrayList<GameObject>( list );
		  Collections.sort(warriorList, new Comparator<GameObject>(){
			  public int compare(GameObject one, GameObject other){
				  
				  return new Integer((int)one.position.y).compareTo(new Integer((int)other.position.y));
			  }
			  
			  
		  });
		  
		  return warriorList;
		  
	  }
	  
	 
		
}
